package telas;

import dao.ConfigSistemaDao;
import java.awt.Toolkit;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import modelo.ConfigSistema;
import modelo.Usuarios;
import telas.clientes.Fr_cliente;
import telas.config.Fr_Configuracao;
import telas.funcionarios.Fr_funcionario;
import telas.recibo.Fr_recibo;
import telas.recibo.Fr_relRecibos;
import telas.usuarios.Fr_usuarios;
import util.Utilitario;

/**
 * @author gilberto.costa 01/12/2011
 */
public class Index extends javax.swing.JFrame {

    public static Usuarios usuarioLogado;
    public static Fr_usuarios fr_usuario = null;
    public static Fr_Configuracao fr_config = null;
    public static Fr_funcionario fr_funcionarios = null;
    public static Fr_cliente fr_clientes = null;
    public static Fr_recibo fr_recibos = null;
    public static Fr_relRecibos fr_relRecibos = null;

    public Index(Usuarios usu) {
        super();
        usuarioLogado = usu;
        initComponents();
        permissoes.Permissao.Permissoes();
        setSize(Toolkit.getDefaultToolkit().getScreenSize().width, (Toolkit.getDefaultToolkit().getScreenSize().height) - 30);
        jPanel1.setSize(Toolkit.getDefaultToolkit().getScreenSize().width, 50);
        Utilitario.eventosteclado(jLabel1, "Index", rootPane);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDesktopPane1 = new javax.swing.JDesktopPane();
        jPanel1 = new javax.swing.JPanel();
        MnUsuario = new javax.swing.JButton();
        MnConfig = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        MnConfig1 = new javax.swing.JButton();
        MnConfig2 = new javax.swing.JButton();
        MnConfig3 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Impressão de Recibos");
        setResizable(false);

        jDesktopPane1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jPanel1.setBackground(new java.awt.Color(230, 229, 228));

        MnUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/kuser.png"))); // NOI18N
        MnUsuario.setText("Usuários");
        MnUsuario.setToolTipText("Cadastro de Usuários");
        MnUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnUsuarioActionPerformed(evt);
            }
        });

        MnConfig.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/advancedsettings.png"))); // NOI18N
        MnConfig.setText("Configurações");
        MnConfig.setToolTipText("Configurações do sistema");
        MnConfig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnConfigActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/funcionario.jpg"))); // NOI18N
        jButton2.setText("Funcionários");
        jButton2.setToolTipText("Cadastro de funcionários");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/clientes.jpg"))); // NOI18N
        jButton3.setText("Clientes");
        jButton3.setToolTipText("Cadastro de clientes");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/recibo.jpg"))); // NOI18N
        jButton4.setText("Recibos");
        jButton4.setToolTipText("Impressão de recibos");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        MnConfig1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Button Close.png"))); // NOI18N
        MnConfig1.setText("Sair");
        MnConfig1.setToolTipText("Sair do sistema");
        MnConfig1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnConfig1ActionPerformed(evt);
            }
        });

        MnConfig2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/relatorio.jpg"))); // NOI18N
        MnConfig2.setText("Relatório");
        MnConfig2.setToolTipText("Reimpressão de recibos / relatório");
        MnConfig2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnConfig2ActionPerformed(evt);
            }
        });

        MnConfig3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Button Close.png"))); // NOI18N
        MnConfig3.setText("Contato");
        MnConfig3.setToolTipText("Sair do sistema");
        MnConfig3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnConfig3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(MnUsuario)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(MnConfig2, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(MnConfig)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(MnConfig1, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 92, Short.MAX_VALUE)
                .addComponent(MnConfig3, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(MnConfig, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(MnUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(MnConfig1, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)
                    .addComponent(MnConfig2, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)
                    .addComponent(MnConfig3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel1.setBounds(0, 0, 1110, 70);
        jDesktopPane1.add(jPanel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1109, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel1)
                .addContainerGap(1084, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                .addGap(3, 3, 3)
                .addComponent(jLabel1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void MnUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnUsuarioActionPerformed
        AbreFrameUsuario();
    }//GEN-LAST:event_MnUsuarioActionPerformed

    private void MnConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnConfigActionPerformed
        AbreFrameConfiguracao();
    }//GEN-LAST:event_MnConfigActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        AbreFrameFuncionario();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        AbreFrameCliente();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        AbreFrameRecibo();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void MnConfig1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnConfig1ActionPerformed
        int opcao;
        Object[] botoes = {"Sair", "Cancelar"};
        opcao = JOptionPane.showOptionDialog(null, "Confirma sair do sistema?",
                "Confirmação!", JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, botoes, botoes[0]);
        if (opcao == JOptionPane.YES_OPTION) {
            System.exit(0);
        }
    }//GEN-LAST:event_MnConfig1ActionPerformed

    private void MnConfig2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnConfig2ActionPerformed
        AbreFrameRelatortioRecibos();
    }//GEN-LAST:event_MnConfig2ActionPerformed

    private void MnConfig3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnConfig3ActionPerformed
        JOptionPane.showMessageDialog(null, "Telefone para contato: (67) 9998-5927\n"
                + "MSN: gilberto.gmc@hotmail.com", "Contato!!", JOptionPane.NO_OPTION);
    }//GEN-LAST:event_MnConfig3ActionPerformed
    private static JInternalFrame getActiveFrame(JDesktopPane desktop) {
        // Obtem o vetor de todos os JInternalFrame no layer superior
        JInternalFrame[] f = desktop.getAllFramesInLayer(0);
        return f.length > 0 ? f[0] : null;
    }

    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Index.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Index.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Index.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Index.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Index(usuarioLogado).setVisible(true);
            }
        });
    }

    private void AbreFrameUsuario() {
        try {
            if (fr_usuario == null) {
                fr_usuario = new Fr_usuarios();
                jDesktopPane1.add(fr_usuario);
            }
            fr_usuario.toFront();
            fr_usuario.setVisible(true);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro: " + e);
        }
    }

    private void AbreFrameRelatortioRecibos() {
        try {
            if (fr_relRecibos == null) {
                fr_relRecibos = new Fr_relRecibos();
                jDesktopPane1.add(fr_relRecibos);
            }
            fr_relRecibos.toFront();
            fr_relRecibos.setVisible(true);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro: " + e);
        }
    }

    private void AbreFrameCliente() {
        try {
            if (fr_clientes == null) {
                fr_clientes = new Fr_cliente();
                jDesktopPane1.add(fr_clientes);
            }
            fr_clientes.toFront();
            fr_clientes.setVisible(true);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro: " + e);
        }
    }

    private void AbreFrameRecibo() {
        try {
            if (fr_recibos == null) {
                fr_recibos = new Fr_recibo();
                jDesktopPane1.add(fr_recibos);
            }
            fr_recibos.toFront();
            fr_recibos.setVisible(true);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro: " + e);
        }
    }

    private void AbreFrameConfiguracao() {
        try {
            if (fr_config == null) {
                fr_config = new Fr_Configuracao();
                jDesktopPane1.add(fr_config);
            }
            fr_config.toFront();
            fr_config.setVisible(true);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro: " + e);
        }
    }

    private void AbreFrameFuncionario() {
        try {
            if (fr_funcionarios == null) {
                fr_funcionarios = new Fr_funcionario();
                jDesktopPane1.add(fr_funcionarios);
            }
            fr_funcionarios.toFront();
            fr_funcionarios.setVisible(true);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro: " + e);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JButton MnConfig;
    public static javax.swing.JButton MnConfig1;
    public static javax.swing.JButton MnConfig2;
    public static javax.swing.JButton MnConfig3;
    public static javax.swing.JButton MnUsuario;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    public static javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
